import datetime
from applications.extensions import db


# 病害百科表
class Wiki(db.Model):
    __tablename__ = "pest_wiki"
    disease_num = db.Column(db.Integer, primary_key=True, autoincrement=True)  # ID
    disease_name = db.Column(db.String(200), nullable=False, comment='病名')  # 病名
    disease_harm = db.Column(db.Text, nullable=False, comment='危害')  # 危害
    disease_symptom = db.Column(db.Text, nullable=False, comment='症状')  # 症状
    disease_prevention = db.Column(db.Text, nullable=False, comment='防治方法')  # 防治方法
    disease_img = db.Column(db.Text, nullable=False, comment='上传的图片')  # 上传的图片
    disease_explain = db.Column(db.Text, nullable=False, comment='说明')  # 说明
    disease_access = db.Column(db.Integer, nullable=False, comment='访问次数')  # 访问次数

    def __init__(self, disease_name, disease_harm, disease_symptom, disease_prevention, disease_img, disease_explain,
                 disease_access):
        self.disease_name = disease_name
        self.disease_harm = disease_harm
        self.disease_symptom = disease_symptom
        self.disease_prevention = disease_prevention
        self.disease_img = disease_img
        self.disease_explain = disease_explain
        self.disease_access = disease_access

    def update(self, entry):
        self.disease_name = entry.disease_name
        self.disease_harm = entry.disease_harm
        self.disease_symptom = entry.disease_symptom
        self.disease_prevention = entry.disease_prevention
        self.disease_img = entry.disease_img
        self.disease_explain = entry.disease_explain
        self.disease_access = entry.disease_access


# 查询记录
class History(db.Model):
    __tablename__ = "check_history"
    history_id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='id')
    disease_name = db.Column(db.Text, nullable=False, comment='病名')
    search_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='查询时间')
    user_id = db.Column(db.Text, nullable=False, comment='用户名')
    search_acuracy = db.Column(db.Text, nullable=False, comment='准确率')
    search_img = db.Column(db.Text, nullable=False, comment='图片')

    def __init__(self, disease_name, search_time, user_id, search_ccuracy, search_img):
        self.disease_name = disease_name
        self.search_time = search_time
        self.user_id = user_id
        self.search_acuracy = search_ccuracy
        self.search_img = search_img

    def update(self, entry):
        self.disease_name = entry.disease_name
        self.search_time = entry.search_time
        self.user_id = entry.user_id
        self.search_acuracy = entry.search_acuracy
        self.search_img = entry.search_img